{extend name="layouts@base" /}
{block name="head"}
<link rel="stylesheet" href="__STATIC__/mobile/default/css/wallet.css"/>
{/block}
{block name='pageType'}chongzhi{/block}
{block name="main" }
<div class="page-bd">
    <!-- 页面内容-->
    <div class="inputBlock">
        <div class="tips fs60 fw_b color_9">提现金额(元)</div>
        <input type="text" class="fs60 num textBox" id="amount">
        
    </div>

    <div class="money">
        <div class="fs26 color_9">可提现金额￥<span class="color_3 balance_money">{$userInfo['account']['balance_money']}</span></div>
        <span class="fs24 fw_b color_3">手续费<em class="withdraw_fee">0</em>元</span>
        <p class="fs24 tag_active">全部提现</p>
    </div>
    <div class="inputBlock">
        <div class="tips fs60 fw_b color_9">支付密码</div>
        <input type="password" class="fs60 num textBox" id="pay_password">
        <div class="ereBox">
            <img src="__STATIC__/mobile/default/images/login01.png" alt="" data-type="0">
        </div>
    </div>
    <div class="paytype">
        <div class="title fs34 color_3 fw_b">请选择提现银行</div>
        <div class="cells">
        	<div class="banklist">

           </div>
            <a href="{:url('bankAdd')}" class="cell">
                <div class="cell_hd"><img src="__STATIC__/mobile/default/images/add.png" alt=""></div>
               <div class="cell_bd"><span class="fs30 color_3 fw_b">添加银行卡</span></div>
            </a>
        </div>
    </div>
    <div class="button fs32 fw_b color_w BGcolor_r postBtn">确认提现</div>

</div>
{literal}
<script type="text/html" id="liTpl">
{{each list as item index}}

<div class="cell">
	
	{{if item.type == 'bank'}}
		<div class="cell_hd"><label for="s_{{item.account_id}}"><img src="__STATIC__/mobile/default/images/{{item.bank_code}}Bank.png" alt=""></label></div>
		<div class="cell_bd"><label for="s_{{item.account_id}}"><span class="fs30 color_3">{{item.bank_name}}({{item.bank_card_number}})</span></label></div>		
	{{/if}}	
	{{if item.type == 'alipay'}}
		<div class="cell_hd"><label for="s_{{item.account_id}}"><img src="__STATIC__/mobile/default/images/AliPay.png" alt=""></label></div>
		<div class="cell_bd"><label for="s_{{item.account_id}}"><span class="fs30 color_3">支付宝({{item.alipay_account}})</span></label></div>		
	{{/if}}
	{{if item.type == 'wechat'}}
	<div class="cell_hd"><label for="s_{{item.account_id}}"><img src="__STATIC__/mobile/default/images/weixinPay.png" alt=""></label></div>
	<div class="cell_bd"><label for="s_{{item.account_id}}"><span class="fs30 color_3">微信({{item.weixinpay_account}})</span></label></div>		
	{{/if}}
	<div class="cell_ft">
	<label for="s_{{item.account_id}}">
		<div class="iconBox">
			<input type="radio" class="check" value="{{item.account_id}}" name="account_id" id="s_{{item.account_id}}" >
			<i class="icon_checked"></i>
		</div>
	</label>
	</div>
</div>
{{/each}}
</script>
{/literal}
{/block}

{block name="footer"}
<script>
$(function() {
	
	$('.textBox').on('click',function(){
		$(this).siblings("div").animate({'fontSize':'0.173333rem','top':'0.2666666rem'})
		$(this).siblings("span").show()
    })
    $('.inputBlock input').blur(function(){
		if($(this).val()==''){
		  $(this).siblings("div").animate({'fontSize':'0.4rem','top':'0.386667rem'})
		  $(this).siblings("span").hide()
		}
	})	
	//加载列表
	jq_ajax('{:url("member/api.withdraw/getList")}','',function(res){
		if (res.code == 0){
			_alert(res.msg);
			return false;
		}
		$('.banklist').html(template('liTpl', res));
		container();
	});

	//验证提现
	function evalFee(){
		var amount = $('#amount').val();
		if (amount < 0){
			$('.withdraw_fee').html(0);
			return false;	
		}
		jq_ajax('{:url("member/api.withdraw/checkWithdraw")}','amount='+amount,function(res){
			if (res.code == 0){
				_alert(res.msg);
				return false;
			}
			$('.withdraw_fee').html(res.withdraw_fee);
		})
	}
	//提现金额变动执行
	$('#amount').change(function(){
		evalFee();
	})
	$('.tag_active').click(function(){
		$('#amount').val($('.balance_money').html()).trigger('click');
		evalFee();
	})
	//end
	//提交提现申请
	$('.postBtn').click(function(){
		var arr = new Object();
		arr.account_id = $('input[name="account_id"]:checked').val();
		arr.amount = $('#amount').val();
		arr.pay_password = $('#pay_password').val();
		if (arr.amount < 1){
			_alert('请输入提现金额.');
			return false;	
		}
        if (arr.pay_password.length != 6){
            _alert('请写6位长度的支付密码.');
            return false;
        }
		if (arr.account_id < 1){
			_alert('请选择提现方式.');
			return false;	
		}
		jq_ajax('{:url("member/api.withdraw/postWithdraw")}',arr,function(res){
			if (res.code == 0){
				_alert(res.msg);
				return false;
			}
			_alert(res.msg,'{:url("member/wallet/balance")}')
		})
	})
    $('.ereBox').on('click',function(){
        let obj=$(this).find('img')
        if(obj.attr('data-type')=='0'){
            obj.attr('src','__STATIC__/mobile/default/images/login02.png')
            obj.attr('data-type','1')
            $(this).siblings('input').attr('type','text')
        }else{
            obj.attr('src','__STATIC__/mobile/default/images/login01.png')
            obj.attr('data-type','0')
            $(this).siblings('input').attr('type','password')
        }
    })
})
</script>
{/block}